package io.output;

import org.junit.Test;

import java.io.*;

/**
 * @author mubei
 * @date 2021/12/3
 * @description
 */
public class BufferedInputOutputStream_ {

    // 需要一张照片
    @Test()
    public void test1() {
        String source = "D:\\date\\distable\\practice\\code\\basic\\src\\main\\java\\io\\sg.jpg";
        String target = "D:\\date\\distable\\practice\\code\\basic\\src\\main\\java\\io\\sgg.jpg";
        BufferedInputStream inputStream = null;
        BufferedOutputStream outputStream = null;
        try {
            inputStream = new BufferedInputStream(new FileInputStream(source));
            outputStream = new BufferedOutputStream(new FileOutputStream(target));
            byte[] buff = new byte[1024];
            int readLen = 0;
            while((readLen = inputStream.read(buff))!= -1){
                outputStream.write(buff, 0, readLen);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {

            try {
                inputStream.close();
                outputStream.close();
            } catch (Exception e) {
                e.printStackTrace();
            }

        }

    }
}
